<template>
	<view class="page">
		<view class="news_list">
			<view class="news_item" v-for="item in newList" :key="item.id" @click="toDetail(item.id)">
				<view style="display: flex;">
					<image :src="getImageUrl(item.img)"></image>
					<view class="news_type">{{item.type==0? "权益":"新闻"}}</view>
				</view>
				<view class="news_title">{{item.title}}</view>
				<view class="news_date">{{item.atime}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getNewsList, getImageUrl} from '@/api/home'
	export default {
		name:"new-list",
		data() {
			return {
				param:{},
				newList:[]
			}
		},
		mounted(){
			this.getNews();
		},
		methods: {
			getNews(){
				this.param.token = uni.getStorageSync("token");
				getNewsList(this.param).then(res => {
					this.newList = res.newsList
					console.log("--------》新闻",res)
				})
			},
			toDetail(id){
				uni.navigateTo({
					url:"/pages/index/news/detail?id=" + id
				})
			},
			getImageUrl(src){
				return this.domain + src;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100%;
		.news_list {
			display: flex; //一行显示
			flex-wrap: wrap;
			justify-content: space-between;
			.news_item {
				background-color: #f5f5f5;
				height: 300rpx;
				width: 48vw;
				margin: 5rpx 0;
				border-radius: 10rpx;
				.news_type {
					background-color: #1890ff;
					width: 80rpx;
					height: 50rpx;
					padding: 3rpx 10rpx;
					color: #FFFFFF;
					margin-left: -360rpx;
					margin-top: 10rpx;
					border-radius: 8rpx;
				};
				image{
					height: 200rpx;
				};
				.news_title {
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
					justify-content: center;
					font-size: 30rpx;
					margin: 5rpx 0;
				};
				.news_date {
					margin: 5rpx 0;
					color: #999999;
				}
			}
		}
	}
</style>
